package com.kedacom.freedomLabel.model.bean;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.kedacom.freedomLabel.excel.IRowRecord;
import com.kedacom.freedomLabel.model.db.Converters;
import com.kedacom.freedomLabel.utils.Cn2Spell;
import com.kedacom.freedomLabel.utils.Utils;

/**
 * @author licheng
 * @since 2019/11/20 16:42
 */
@Entity
public class Category extends IFirstLetter implements IRowRecord {

    @NonNull
    @PrimaryKey
    public String uuid = Converters.randomUUID();

    // 分类名称
    public String name;

    // 缩写（拼音首字母）
    public String shortHand;

    // 分类编号
    public String number;

    // 六个Item的别名
    public String[] columnNames;

    // 是否启用
    public Boolean[] status;

    // 必填
    public Boolean[] required;

    // 创建时间
    public Long createTime;

    // 更新时间
    public Long updateTime;

    @Override
    public String toString() {
        return name;
    }

    @Override
    public String getFirstLetter() {
        if (TextUtils.isEmpty(this.name)) {
            return "#";
        }
        String firstLetter = Cn2Spell.getPinYin(this.name).substring(0, 1).toUpperCase();
        if (!firstLetter.matches("[A-Z]")) {
            return "#";
        }
        return firstLetter;
    }

    @Override
    public String getItemName() {
        return this.name;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (obj instanceof Category) {
            Category other = (Category) obj;
            return TextUtils.equals(this.uuid, other.uuid);
        }
        return false;
    }

    @NonNull
    @Override
    public String[] rowValues() {
        return new String[]{number,name, Utils.toArrayString(columnNames),Utils.toArrayString(status),Utils.toArrayString(required)};
    }

    @Override
    public boolean[] isNumber() {
        return new boolean[0];
    }
}